package com.portal.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.portal.entity.Feedback;
import com.portal.mapper.FeedbackMapper;
import com.portal.service.FeedbackService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 反馈服务实现类
 */
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {
    
    private static final Logger log = LoggerFactory.getLogger(FeedbackServiceImpl.class);
    
    @Override
    public boolean submitFeedback(Feedback feedback) {
        // 处理图片信息
        if (feedback.getImage() != null && !feedback.getImage().isEmpty()) {
            try {
                // 解析图片JSON字符串
                ObjectMapper mapper = new ObjectMapper();
                JsonNode imageNode = mapper.readTree(feedback.getImage());
                
                // 直接从JSON对象中获取字段
                feedback.setImage(imageNode.get("url").asText());
                feedback.setImageName(imageNode.get("name").asText());
                feedback.setImageUrl(imageNode.get("url").asText());
                feedback.setFileSize(imageNode.get("size").asLong());
                feedback.setFileType(imageNode.get("type").asText());
                
            } catch (Exception e) {
                log.error("处理图片信息失败", e);
            }
        }
        
        return save(feedback);
    }
    
    @Override
    public List<String> getFeedbackTypes() {
        return Arrays.asList(
            "产品咨询",
            "技术支持",
            "商务合作",
            "投诉建议",
            "其他"
        );
    }
    
} 